
from guiCommon import LeVinToggleButton, BottleWidget
from kivy.properties import  ObjectProperty, NumericProperty
from kivy.uix.boxlayout import BoxLayout

import guiCommon
import  wineAreasWidget
from world.worldArea import RegionArea, CountryArea
from world.bottle import Bottle

class LeVinSidePanel(BoxLayout):

    selectedObject = ObjectProperty(None)
    
    def __init__(self, **kargs):
        super(LeVinSidePanel, self).__init__(**kargs)
        self.bottleTab = guiCommon.LeVinTabLayout()
        self.areaTab = guiCommon.LeVinTabLayout()        

        
    def getWidgetForNode(self, node):
        if node.__class__ is Bottle:
            return self.bottleTab
        else:
            return self.areaTab

    def on_selectedObject(self, o, node):
        wid = self.getWidgetForNode(node)
        self.clear_widgets()
        self.add_widget(wid)



#import os.path
import levinCommon
class AreaDisplay(BoxLayout):
    area = ObjectProperty(None)

    def __init__(self, **kargs):
        super(AreaDisplay, self).__init__(**kargs)    
        wineAreasWidget.theTree.bind(_selected_node = self.on_node_selected)

    def on_node_selected(self,o,node):
        if node.__class__ in [RegionArea, CountryArea]:
            self.area = node
        
    def image_path(self, area):
        if not area:
            return ''
        p = area.dataPath()
        p = p.replace('data/World_','')
        p = levinCommon.dataPath(p+'_vineyards.png')
        print '  ------> imagepath =', p
        return p

from kivy.factory import Factory
for cls in [ LeVinSidePanel, AreaDisplay]:
    Factory.register(cls.__name__, cls=cls)

from kivy.lang import Builder
guiCommon.load_kv_file('sidePanel.kv')
            



